
/**
 * @author LKQ
 * @date 2021/12/12 16:27
 * @description
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] nums = {4, 5};
        int val = 5;
        solution.removeElement(nums, val);
    }

    public int removeElement(int[] nums, int val) {
        int fast = 0, slow = 0, n = nums.length;
        while (fast < n) {
            if (nums[fast] != val && nums[slow] != val) {
                fast++;
                slow = fast;
            }else  if (nums[fast] == val ){
                fast++;
            }else if (nums[fast] != val && nums[slow] == val){
                int temp = nums[fast];
                nums[fast] = nums[slow];
                nums[slow] = temp;
                slow++;
                fast++;
            }
        }
        return slow;
    }
}
